package edu.ycxy.poetry.controller;


import edu.ycxy.poetry.entity.BookLei;
import edu.ycxy.poetry.service.IBookLeiService;
import edu.ycxy.poetry.service.IDjInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @Author @xin
 * @createDate 2022/3/15
 * @Description
 */
@RestController
@RequestMapping("/booklei")
@Slf4j
public class BookLeiController {

    @Autowired
    private IBookLeiService bookLeiService;
    @Autowired
    private IDjInfoService djInfoService;


    //根据vab_dj_list中的id 对应 vab_dj_info 中的 aid ,查询古籍的主标题,如果查询结果为空,则说明没有主标题,直接在 vab_dj_info中查询次标题
    @RequestMapping("/selectList/{aid}")
    public HashMap<String, List> selectListToInfo(@PathVariable("aid") Integer aid){
        HashMap<String, List> hs = new HashMap<>();
        List<BookLei> bookLeis = bookLeiService.selectListToInfo(aid);
        if (bookLeis.isEmpty() || bookLeis.size()==0){
            //log.debug("获取的标题1:"+djInfoService.selectList(aid));
            hs.put("",djInfoService.selectList(aid));
            //log.debug("获取的map1:"+hs);
            //map.put(0,djInfoService.selectList(aid));
        }else {
            for (BookLei bookLei : bookLeis) {
                //log.debug("id为:"+bookLei.getId());
                //log.debug("获取的次标题为:"+djInfoService.selectListById(bookLei.getId()).getClass());
                //log.debug("获取的标题为:"+bookLei.getName());
                hs.put(bookLei.getName(),djInfoService.selectListById(bookLei.getId()));
            }
        }
        log.debug("获取的map数据:"+hs);
        return hs;
       }
}
